rm(list=ls())
# Check that required packages are installed:
want = c("foreign", "reshape2", "dplyr", "here")
have = want %in% rownames(installed.packages())
if ( any(!have) ) { install.packages( want[!have] ) }
# load packages
junk <- lapply(want, library, character.only = TRUE)
rm(have,want,junk)

options(scipen = 999)
load("allmodels.RData")


# Descriptives
v.d <- c("dist_diff", "otherside_ch", "pid", "antipid", "lrext_cen",
         "edlow", "edhigh", 
         "polint_cen", "polinfo_cen", "n_parties_medcen", "ch_polar", 
         "ri_l2_m")
subset(data, sameside_ch == 1 | otherside_ch == 1, select = v.d) %>% 
  melt(variable.name = "var") %>% 
  group_by(var) %>%
  summarize_all(funs(n(), mean, sd, median, min, max))
